package cn.iocoder.yudao.module.voice.cc.config;

import cn.iocoder.yudao.module.voice.cc.fs.FsListen;
import cn.iocoder.yudao.module.voice.cc.cache.CacheService;
import cn.iocoder.yudao.module.voice.cc.command.GroupHandler;
import cn.iocoder.yudao.module.voice.cc.tcp.TcpServer;
import cn.iocoder.yudao.module.voice.cc.websocket.WebSocketManager;
import cn.iocoder.yudao.module.voice.cc.websocket.handler.WsMonitorHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author 徐利民
 * @date 2023/12/20 10:37
 */
@Component
@Slf4j
public class InitFreeswitchBean implements InitializingBean {

    @Autowired
    private WebSocketManager webSocketManager;

    @Autowired
    private FsListen fsListen;

    @Autowired
    private GroupHandler groupHandler;

    @Autowired
    private WsMonitorHandler wsMonitorHandler;

    @Autowired
    private CacheService cacheService;

    @Autowired
    private TcpServer tcpServer;

    @Value("${subscribe.agent.state:false}")
    private Boolean agentState;

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("################初始化开始#################");
        cacheService.initCompany();
        webSocketManager.start();
        fsListen.start();
        groupHandler.start();
        wsMonitorHandler.start();
        //开启tcp订阅坐席状态
        if (agentState) {
            tcpServer.start();
        }
        log.info("################初始化结束#################");
    }
}
